//
//  MHRepoViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/5/12.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHRepoViewController.h"
#import "MHCommonCell.h"
#import "MHRepoViewModel.h"

@interface MHRepoViewController ()
@property(nonatomic, assign) NSIndexPath *indexPath;

@property(nonatomic, strong)  MHRepoViewModel *viewModel;

@end

@implementation MHRepoViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
}


-(void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object
{
    MHCommonItemViewModel *model = (MHCommonItemViewModel *)object;
    if (indexPath == self.indexPath) {
        model.isSelected = true;
    }else
    {
        model.isSelected = false;
    }
    [cell bindViewModel:object];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.indexPath = indexPath;
    [self.tableView reloadData];
}
-(void)bindViewModel
{
    [super bindViewModel];
    
    
}

-(void)rightButtonClick
{
    if (self.indexPath) {
        MHCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[self.indexPath.section];
        MHCommonItemViewModel *object = groupViewModel.itemViewModels[self.indexPath.row];
        [self.viewModel.repoCommand execute:object.title] ;
    }
}

@end
